import requests
from bs4 import BeautifulSoup as bs
from  chaojiying import  Chaojiying_Client
url = 'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
headers= {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0'
}
response = requests.get(url=url,headers=headers)
content=response.text
soup = bs(content,'lxml')
# 获取__VIEWSTATE
VIEWSTATE = soup.select('#__VIEWSTATE')[0].attrs.get('value')
VIEWSTATEGENERATOR = soup.select('#__VIEWSTATEGENERATOR')[0].attrs.get('value')
# 获取验证码图片
conde = soup.select('#imgCode')[0].attrs.get('src')
code_url = 'https://so.gushiwen.cn/'+conde
# 使用session保存图片
session = requests.Session()
code_response = session.get(code_url)
code_content=code_response.content
with open('code.jpg','wb') as fp:
    fp.write(code_content)
# 手动输入验证码
# code_name = input('请输入你的验证码')
# 通过超级鹰获取验证码
chaojiying = Chaojiying_Client('jepusi', 'Aliyun@163.com', '959483')
img = open('code.jpg','rb').read()
code_name = chaojiying.PostPic(img,1902).get("pic_str")
url_post = 'https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx'
data_post = {
    '__VIEWSTATE': 'gEx3LheG63nanGKYLBTaucuyVISpmFOgDKTxhagL00XVntxv6ydsptVXCYSRa+l5hk9BQm+IkCh2Tzn3lkv2p8060dRCESBukwrdGhgjoMksh3wcONIgY5tDXO01ewyQJ1PZFldmJL8wgFr5RkFFQJCVFAw=',
    '__VIEWSTATEGENERATOR': 'C93BE1AE',
    'from': 'http://so.gushiwen.cn/user/collect.aspx',
    'email': '18027761141@163.com',
    'pwd': '19970926ccc',
    'code': code_name,
    'denglu': '登录'
}
response_post = session.post(url=url,data=data_post,headers=headers)
content_post = response_post.text
with open('gushiwen.html','w',encoding='utf') as fp:
    fp.write(content_post)